<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/9
 * Time: 14:43
 */
include '../classes/conn.php';
include "../classes/logincheck.php";
if(islogin()=="teacher_login"){
    $class_num=$_POST['class_num'];
    $stu_num=$_POST['stu_num'];
    $stu_name=$_POST['stu_name'];
    $psw = md5(substr($stu_num, -6));
//    判断学生是否存在
    $query1="select num from student where num='{$stu_num}' and class='{$class_num}' and teacher='{$_SESSION['t_num']}'";
    $res=mysql_query($query1);
    if(mysql_num_rows($res)){
        die("exist");
    }
    $query="insert into student (num,name,class,teacher,psw) 
values ('{$stu_num}','{$stu_name}','{$class_num}','{$_SESSION['t_num']}','{$psw}')";
    $res=mysql_query($query);
    if(!$res){
        echo "0";
    }
    else echo "1";
}
else echo "0";